import { ajax } from '@/utils/utils';
import config from '@/../config';

//获取我的草稿箱中的专栏草稿列表
export const getDraftList = async (params) => {
  const res = await ajax(
    'https://member.bilibili.com/x/web/draft/list',
    'get',
    null,
  );
  return res;
};

//读取我的学习列表的内容
export const getContent = async (params) => {
  const { aid } = params;
  const res = await ajax(
    'https://api.bilibili.com/x/article/creative/draft/view',
    'get',
    { aid },
  );
  return res;
};

//更新我的学习列表的内容
export const setContent = async (params) => {
  const { data = {}, aid = '', csrf = '' } = params;
  const res = await ajax(
    'https://api.bilibili.com/x/article/creative/draft/addupdate',
    'POST',
    {
      title: config.myOnlineClassName,
      banner_url: '',
      content: JSON.stringify(data) || '',
      words: 120,
      category: 34,
      list_id: 0,
      tid: 4,
      reprint: 0,
      tags: '',
      image_urls: '',
      origin_image_urls: '',
      dynamic_intro: '',
      media_id: 0,
      spoiler: 0,
      original: 0,
      top_video_bvid: '',
      aid,
      csrf,
    },
  );
  return res;
};

//创建专栏为我的学习类别
export const createColumn = async (params) => {
  const res = await ajax(
    'https://api.bilibili.com/x/article/creative/draft/addupdate',
    'post',
    {
      title: config.myOnlineClassName,
      banner_url: '',
      content: '',
      summary: '',
      words: 0,
      category: 0,
      tid: 4,
      reprint: 0,
      tags: '',
      image_urls: '',
      origin_image_urls: '',
      dynamic_intro: '',
      media_id: 0,
      spoiler: 0,
      original: 0,
      top_video_bvid: '',
      csrf: params.csrf, //暂时写死
    },
  );
  return res;
};
